<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.jsp' starting page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<script src="./js/jquery-3.3.1.min.js" type="text/javascript" charset="utf-8"></script>
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<style type="text/css">
	#upLoad{
		height: 100px;
		border: 1px solid #2C3E50;
		width: 100px;
		display:none ;
	}
</style>
  </head>
 
  <body>
   <c:if test="${empty sessionScope.types}">
  	<c:redirect url="add.do"></c:redirect>
  </c:if>
   <c:if test="${!empty sessionScope.types}">
  	
  	<h1>判断有问题</h1>
  </c:if>
    <form action="add.do" method="post" enctype="multipart/form-data">
    	标题：<input type="text" name="title" id="title" value="" /><br>
		作者：<input type="text" name="author" id="author" value="" /><br>
		标题图片：  <input name="file" type="file" style="width: 70px;" accept=".jpg,.png"/>
				<img alt="请选择图片" src="" id="upLoad"><br>
		摘要：<input type="text" name="summary" id="summary" value="" /><br>
		内容：<textarea rows="4" cols="100" name="content"></textarea><br/>
		文章类型：	<select name="type">
				<c:forEach items="${types}" var="itme">
					<option value="${itme.tid }">${itme.tName}</option>
				</c:forEach>
				
				</select><br/>
    	<button type="submit">提交</button>
    </form>
    <a href="backstage/list.jsp">返回到文章列表</a>
	<script type="text/javascript">

	$("input[name=file]").change(function(){
		var imgObj=this.files[0];
		if(imgObj!=undefined){
			var reader=new FileReader();
			reader.readAsDataURL(imgObj);
			reader.onload=function(){
				$("#upLoad").attr({"src":reader.result});
				$("#upLoad").show();
			}
		}else{
			$("#upLoad").hide();
		}
		
	})
	</script>
  </body>
</html>
